from datetime import datetime
from django.db import models
from article.models import Article
from user.models import UserModel


# Create your models here.
# 文章评论表
class Content(models.Model):
    contenter = models.ForeignKey(UserModel,to_field='uid', related_name="user2", on_delete=models.CASCADE,db_column="contenter_id") # 用户外键
    art= models.ForeignKey(Article,to_field='aid', related_name="article2", on_delete=models.CASCADE,db_column="art_id")  # 文章外键
    comment = models.TextField()    # 评论内容
    createTime = models.DateTimeField(default=datetime.now)
    class Meta:
        db_table = "content"
        verbose_name = "评论表"  # 在admin站点显示名称


"""
related_name:反向查询
"""
#  评论回复表
class Reply(models.Model):
    content = models.ForeignKey(Content,related_name="reply1",on_delete=models.CASCADE,db_column="content_id")  # 评论id
    replyer = models.ForeignKey(UserModel,to_field="uid",related_name="user3",on_delete=models.CASCADE,db_column="replyer_id")  # 回复者id
    comment = models.TextField()    # 回复内容
    createTime = models.DateTimeField(default=datetime.now)
    class Meta:
        db_table = "reply"
        verbose_name = "回复表"
